package com.minhua.jijiehao2.mainframe.common.shareactivity.impl

import android.text.TextUtils
import com.minhua.jijiehao2.base.BaseMvpPresenter
import com.minhua.jijiehao2.bean.BaseBean
import com.minhua.jijiehao2.bean.ShareInfoBean
import com.minhua.jijiehao2.constants.DefineKey
import com.minhua.jijiehao2.http.CallBack
import com.minhua.jijiehao2.http.ParamsMap
import com.minhua.jijiehao2.mainframe.common.shareactivity.imp.ISharePresenter
import com.minhua.jijiehao2.mainframe.common.shareactivity.imp.IShareView
import com.minhua.jijiehao2.utils.SPUtils
import com.minhua.jijiehao2.utils.T


class SharePresenter : BaseMvpPresenter<IShareView>(), ISharePresenter {

    private val mShareModel = ShareModel()

    override fun getShareInfo() {
        val map = ParamsMap()
        map.put(DefineKey.USER_ID, SPUtils.get(DefineKey.USER_ID, ""))
        map.put(DefineKey.SHARE_FLAG, 0)
        mShareModel.getShareInfo(map, object : CallBack<ShareInfoBean>() {
            override fun onSuccess(t: BaseBean<ShareInfoBean>) {
                v?.onShareInfoSuccess(t.data!!)
            }
        })
    }

    override fun setAddress() {
        val name = v?.getName() ?: ""
        val tel = v?.getTel() ?: ""
        val address = v?.getAddress() ?: ""
        if (TextUtils.isEmpty(name)) {
            T.showShort("姓名不能为空")
            return
        }
        if (TextUtils.isEmpty(tel)) {
            T.showShort("电话不能为空")
            return
        }
        if (TextUtils.isEmpty(address)) {
            T.showShort("地址不能为空")
            return
        }
        val map = ParamsMap()
        map.put(DefineKey.USER_ID, SPUtils.get(DefineKey.USER_ID, ""))
        map.put("consignee", name)
        map.put("tel", tel)
        map.put("address", address)
        map.put(DefineKey.SHARE_FLAG, "0")
        mShareModel.setAddress(map, object : CallBack<Any>() {
            override fun onSuccess(t: BaseBean<Any>) {
                v?.onAddressSuccess()
            }
        })
    }
}